import { createRouter, createWebHistory } from "vue-router";
import { useDashboardStore } from "../store";
import { ElMessageBox } from "element-plus";

const store = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: "/",
      component: () => import("../pages/XmHome/index.vue"),
      children: [
        {
          path: "/class",
          component: () => import("../views/XmClass/index.vue"),
        },
        {
          path: "/classroom",
          component: () => import("../views/XmClassroom/index.vue"),
        },
        { path: "/func", component: () => import("../views/XmFunc/index.vue") },
        { path: "/role", component: () => import("../views/XmRole/index.vue") },
        {
          path: "/staff",
          component: () => import("../views/XmStaff/index.vue"),
        },
        {
          path: "/student",
          component: () => import("../views/XmStudent/index.vue"),
        },
        { path: "/user", component: () => import("../views/XmUser/index.vue") },
      ],
    },
    { path: "/login", component: () => import("../pages/XmLogin/index.vue") },
  ],
});

// store.beforeEach((to, from, next) => {
//   const dashboardStore = useDashboardStore();
//   if (sessionStorage.getItem("token")) {
//     if (to.path === "/login") {
//       next("/");
//     } else {
//       next();
//     }
//   } else if (!sessionStorage.getItem("token")) {
//     ElMessageBox.alert("未登录或登录超时，请重新登录", "提示", {
//       type: "warning",
//       callback: () => next("/login"),
//     });
//   } else if (
//     to.path.slice(1) === "" ||
    // dashboardStore.userFuncs.some(
//       (func) =>
//         func.func_key !== "" && to.path.slice(1).startsWith(func.func_key)
//     )
//   ) {
//     next();
//   } else {
//     ElMessageBox.alert("你访问的页面不存在", "提示", {
//       type: "warning",
//       callback: () => next("/"),
//     });
//   }
  //  else if(to.path==="/404"){

  //   next()
  // }else{
  //   next('/404')
  // }
// });
export default store;
